/**
 * 
 */
package com.yangtao.prototype.system.entity;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import com.yangtao.framework.hibernate.BaseEntity;

/**
 * 组织机构对象
 * 
 * @author 杨涛
 * 
 */
@Entity
@Table(name = "sys_organize")
public class Organize extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 机构编号
	 */
	@Column(length = 20)
	private String orgCode;
	/**
	 * 组织log标志
	 */
	private String logo;

	/**
	 * 机构名称
	 */
	@Column(length = 200)
	private String name;
	/**
	 * 机构类型
	 */
	@Column(length = 20)
	private String type;
	/**
	 * 机构描述
	 */
	private String desription;
	/**
	 * 父机构
	 */
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "supId")
	@Cascade(value = { CascadeType.SAVE_UPDATE })
	private Organize supOrganize;
	/**
	 * 机构所含用户
	 */
	@OneToMany(fetch = FetchType.LAZY)
	private List<SysUser> users;
	/**
	 * 子机构
	 */
	@OneToMany(mappedBy = "supOrganize", fetch = FetchType.LAZY)
	@Cascade( { CascadeType.DELETE })
	private List<Organize> subOrganize;

	public boolean hasChildren() {
		if (this.subOrganize != null && this.subOrganize.size() > 0)
			return true;
		return false;
	}

	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}

	public List<SysUser> getUsers() {
		return users;
	}

	public void setUsers(List<SysUser> users) {
		this.users = users;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * @return the logo
	 */
	public String getLogo() {
		return logo;
	}

	/**
	 * @param logo the logo to set
	 */
	public void setLogo(String logo) {
		this.logo = logo;
	}

	/**
	 * @param type
	 *            the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * @return the desription
	 */
	public String getDesription() {
		return desription;
	}

	/**
	 * @param desription
	 *            the desription to set
	 */
	public void setDesription(String desription) {
		this.desription = desription;
	}

	/**
	 * @return the supOrganize
	 */
	public Organize getSupOrganize() {
		return supOrganize;
	}

	/**
	 * @param supOrganize
	 *            the supOrganize to set
	 */
	public void setSupOrganize(Organize supOrganize) {
		this.supOrganize = supOrganize;
	}

	/**
	 * @return the subOrganize
	 */
	public List<Organize> getSubOrganize() {
		return subOrganize;
	}

	/**
	 * @param subOrganize
	 *            the subOrganize to set
	 */
	public void setSubOrganize(List<Organize> subOrganize) {
		this.subOrganize = subOrganize;
	}

	public Organize() {
		super();
	}

	public Organize(String code, String desription, String name,
			List<Organize> subOrganize, Organize supOrganize, String type) {
		super();
		this.orgCode = code;
		this.desription = desription;
		this.name = name;
		this.subOrganize = subOrganize;
		this.supOrganize = supOrganize;
		this.type = type;
	}

}
